﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

//Superklasse für alle GameObjekte hier wird Position, Model und Kollisionen abgelegt
namespace TronLeapRacing
{
    class GameObject
    {
        public Model model;
        public Vector3 position;
        public bool isActive;
        public BoundingSphere boundingSphere;

        public GameObject()
        {
            model = null;
            position = Vector3.Zero;
            isActive = false;
            boundingSphere = new BoundingSphere();
        }

        protected BoundingSphere calculateBoundingSphere()
        {
            BoundingSphere mergedSphere = new BoundingSphere();
            BoundingSphere[] boundingSpheres;

            int index = 0;
            int meshCount = model.Meshes.Count;

            boundingSpheres = new BoundingSphere[meshCount];

            foreach (ModelMesh mesh in model.Meshes)
            {
                boundingSpheres[index++] = mesh.BoundingSphere;
            }

            mergedSphere = boundingSpheres[0];

            if ((model.Meshes.Count) > 1)
            {
                index = 1;
                do
                {
                    mergedSphere = BoundingSphere.CreateMerged(mergedSphere, boundingSpheres[index]);
                    index++;
                } while (index < model.Meshes.Count);
            }

            mergedSphere.Center.Y = 0;
            return mergedSphere;
        }
    }
}
